<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="app">
        <p>count的值是：{{count}}</p>
        <!-- 如果count是偶数则按钮背景色为红色，否则取消背景色 -->
        <!-- <button @click="add">+N</button> -->
        <!-- vue提供内置变量 $event，他是原生DOM的事件对象e -->
        <button @click="add(1,$event)">+N</button>
    </div>
    <script src="./lib/vue-2.6.12.js"></script>
    <script>
        const vm = new Vue({
            el: '#app',
            data: {
                count: 0,
            },
            methods: {
                add(n, e) {
                    this.count += n
                    console.log(e)

                    // 判断this.count的值是否为偶数
                    if (this.count % 2 === 0) {
                        //偶数
                        e.target.style.backgroundColor = 'red'
                    } else {
                        //奇数
                        e.target.style.backgroundColor = ''
                    }
                }
            }
        })
    </script>
</body>

</html>